#include <winsock2.h>
class NetworkMsg{
    public:
        SOCKET socket;
        char msg[0xff];
        int msg_len;
        sockaddr_in sock_addr;
        int addr_len;
};

class GameMsg{
    public:
    enum{
        CHESS_DOWN=1<<0,
        CHECK_WIN=1<<1,
        CONFIRM_WIN=1<<2,
        YOU_FIRST=1<<3,
        OVERTIME=1<<4,
        TOUCH=1<<5,
        RESPONSE=1<<6
    };
    char type;
    char data[0xff-1];
};

class Network
{
private:
    static WSAData wsaData;
    SOCKET m_socket = INVALID_SOCKET;
    static int af;
    static int protocol;
    static int type;
public:
    Network() = default;
    ~Network();

    static int init();
    static void quit();
    static void setSocketInfo(int af,int type,int protocol);
    bool createSocket();
    bool connect(const char* ip,int port);
    bool bind(int port);
    bool listen(int backlog);
    bool accept(NetworkMsg *networkMsg);
    int recv(SOCKET socket,char* buf, int buffSize,int flags);
    int send(SOCKET socket,const char* buf, int len, int flags);
    SOCKET getSocket();


    
};
